<!--混合模板-->
<template>
  <div/>
</template>
<script>
import { mapGetters, mapState } from 'vuex'
const myMixin = {
  computed: {
    ...mapGetters([
      'curSelectRole', 'permission'
    ]),
    ...mapState('user', {
      userInfo: state => state.userInfo,
      unitList: state => state.unitList,
      excludeList: state => state.excludeList,
      curSelectUnitId: state => state.curSelectUnitId,
      firstUrlParam: state => state.firstUrlParam
    }),
    ...mapState('sys', {
      isLoading: state => state.isLoading,
      isWechat: state => state.isWechat
    })
  },
  data() {
    return {
      isAssignWX: false
    }
  },
  methods: {
    to(name, query, isReplace) {
      query = query || {}
      // if (query.isCheckClassId && !this.curSelectRole.data.classId) {
      //   this.$router.push({ name: 'NotJoinClass' })
      //   return
      // }
      if (!this.$common.checkPermissionByClassId(query.isCheckClassId)) {
        return
      }
      if (name.indexOf('http') > -1 || name.indexOf('https') > -1) {
        location.href = name
      } else {
        if (isReplace) {
          this.$router.replace({ name: name, query: query })
        } else {
          this.$router.push({ name: name, query: query })
        }
      }
    },
    /**
     * 获取当前活动状态
     * @param applyStartTime (报名开始时间)
     * @param applyEndTime (报名结束时间)
     * @param activityStartTime (活动开始时间)
     * @param activityEndTime (活动结束时间)
     */
    getActiveStatus(applyStartTime, applyEndTime, activityStartTime, activityEndTime) {
      const date = new Date()
      const curTimetamp = date.getTime()
      let status = ''
      if (curTimetamp < applyStartTime) {
        status = '活动未开始'
      }
      if (applyEndTime > curTimetamp && curTimetamp > applyStartTime) {
        status = '报名进行中'
      }
      if (activityStartTime > curTimetamp && curTimetamp > applyEndTime) {
        status = '报名已结束'
      }
      if (activityEndTime > curTimetamp && curTimetamp > activityStartTime) {
        status = '活动进行中'
      }
      if (curTimetamp > activityEndTime) {
        status = '活动已结束'
      }
      return status
    },
    /**
     * 获取活动标签列表
     * @param type
     */
    getActionTab(fn) {
      this.$request.get(this.ctx + 'manage/api/v1/app/lzdapplyactivitytag/query/list', { Status: 1 }).then((res) => {
        console.log(res)
        if (fn) {
          fn(res)
        }
      })
    },
    /**
     * 获取审核状态
     * @param value
     * @return
     */
    getVerifyStatus(value) {
      const arr = [
        { name: '待审核 ', val: '1568' },
        { name: '审核通过 ', val: '1569' },
        { name: '审核不通过', val: '1570' },
        { name: '已撤销', val: '1572' }
      ]
      if (value !== '') {
        const tempObj = arr.find((item) => {
          return item.val === value
        })
        return tempObj.name
      }
    },
    /**
     *  主页刷新重新请求数据
     *  @param params
     *  @param fn
     */
    refreshCampus(fn) {
      const { fullPath } = this.$route
      this.$nextTick(() => {
        this.$store.dispatch('campus/EmptyCampus')
        // this.$store.dispatch('user/UpdateExculdeList', list)
        this.$router.replace({
          path: '/redirect' + fullPath
        })
      })
      if (fn) {
        fn()
      }
    },
    /**
     * 清除首页最新消息的缓存并重新请求数据
     * @param key
     */
    setCampus(key) {
      this.$store.dispatch('campus/UpdateCampus', { key: key, isUpdate: true })
    },

    /**
     * 返回校园页
     */
    goCampus(isReplace) {
      isReplace = !!isReplace
      if (isReplace) {
        this.$router.replace({ name: 'Campus' })
      } else {
        this.$router.push({ name: 'Campus' })
      }
    },
    /**
     * 微信环境开启分享
     */
    share(params) {
      // this.WX.share(params)
      console.log(params, 'params')
      if (params.link !== '') {
        params.link = this.domain_ctx + 'wechat/api/v1/wxoauth/redirect/' + this.firstUrlParam.appId + '/' + this.firstUrlParam.unitId + '?url=' + encodeURIComponent(params.link+'&backHome=true')
      } else {
        params.link = this.domain_ctx + 'wechat/api/v1/wxoauth/redirect/' + this.firstUrlParam.appId + '/' + this.firstUrlParam.unitId + '?url=' + encodeURIComponent(window.location.href+'&backHome=true')
      }
      const _this = this
      // eslint-disable-next-line no-undef
      if (!this.isAssignWX) {
        this.WX.config(() => {
          _this.isAssignWX = true
          this.WX.share(params)
        }) // 微信注入权限验证配置
      } else {
        this.WX.share(params)
      }
    }
  },
  created() {
    /**
       * 微信分享（每个页面调用）
       */
    // const params = { title: '', desc: '', link: '', imgUrl: '' }
    // this.WX.share(params)
  }
}
export default { myMixin }
</script>
